package com.stream;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Test03 {
    public static void main(String[] args) {

        ArrayList<String> list1 = new ArrayList<>();
        list1.add("A");
        list1.add("B");
        list1.add("C");
        list1.add("D");
        list1.add("E");

        List<String> stringList = list1.stream().filter(item -> item.equals("A")).collect(Collectors.toList());

        for (String s : stringList) {
            System.out.println(s);
        }

        ArrayList<String> list2 = new ArrayList<>();
        list2.add("B");
        list2.add("D");

        // 比较差值,将数据为null值的排在最后
        List<String> newList = list1.stream()
                .filter(item -> !list2.contains(item))
                .sorted(Comparator.comparing(item -> item, Comparator.nullsLast(String::compareTo)))
                .collect(Collectors.toList());

        for (String s : newList) {
            System.out.println(s);
        }
    }
}
